package com.etone.smartAudit.controller;

import com.etone.smartAudit.dto.productMap.ProductMapDTO;
import com.etone.smartAudit.enums.OnlineState;
import com.etone.smartAudit.service.ProductMapService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.productMap.ProductMapVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author: sovy
 * @date: 2020/12/23
 * @description:
 */
@RestController
@AllArgsConstructor
@Api(tags = "产品地图", value = "ProductMapController")
public class ProductMapController {
    private ProductMapService productMapService;

    @ApiOperation(value = "产品地图列表")
    @GetMapping("/productMaps")
    public PagerVO<ProductMapVO> list(
            @ApiParam(value = "关键字（能力代码、能力名称、适应范围）") @RequestParam(required = false) String key,
            @ApiParam(value = "能力类别") @RequestParam(required = false) List<Integer> abilityTypeIds,
            @ApiParam(value = "产品服务性质") @RequestParam(required = false) List<Integer> serviceNatureIds,
            @ApiParam(value = "编辑开始时间") @RequestParam(required = false) Date startUpdateTime,
            @ApiParam(value = "编辑结束时间") @RequestParam(required = false) Date endUpdateTime,
            @ApiParam(value = "上线状态") @RequestParam(required = false) OnlineState onlineState,
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        return productMapService.list(key, abilityTypeIds, serviceNatureIds, startUpdateTime, endUpdateTime, onlineState, page, pageSize);
    }

    @ApiOperation(value = "产品地图详情")
    @GetMapping("/productMaps/{id}")
    public ProductMapVO detail(@ApiParam(value = "产品地图id") @PathVariable Integer id) {
        return productMapService.detail(id);
    }

    @ApiOperation(value = "增加产品地图")
    @PostMapping("/productMaps")
    public void add(
            @ApiParam(value = "产品地图表单") @RequestBody @Validated ProductMapDTO productMapDTO
    ) {
        productMapService.save(null, productMapDTO);
    }

    @ApiOperation(value = "编辑产品地图")
    @PutMapping("/productMaps/{id}")
    public void edit(
            @ApiParam(value = "产品地图id") @PathVariable Integer id,
            @ApiParam(value = "产品地图表单") @RequestBody @Validated ProductMapDTO productMapDTO
    ) {
        productMapService.save(id, productMapDTO);
    }

    @ApiOperation(value = "删除产品地图")
    @DeleteMapping("/productMaps/{id}")
    public void edit(
            @ApiParam(value = "产品地图id") @PathVariable Integer id
    ) {
        productMapService.delete(id);
    }
}
